﻿<UserControl x:Class="SSLVerifier.Views.UserControls.CertTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vm="clr-namespace:SSLVerifier.API.ViewModels"
             mc:Ignorable="d"
             Background="{StaticResource PanelHeaderBackground}"
             Foreground="Navy"
             d:DataContext="{d:DesignInstance vm:MainWindowVM}">
    <UserControl.Resources>
        <Style x:Key="Img" TargetType="Image">
            <Setter Property="Source" Value="/Views/Images/Misc/normalcert.png"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Value.HasWarnings}" Value="True">
                    <Setter Property="Source" Value="/Views/Images/Misc/warncert.png"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Value.HasErrors}" Value="True">
                    <Setter Property="Source" Value="/Views/Images/Misc/failedcert.png"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Value.IsRoot}" Value="True">
                    <Setter Property="Source" Value="/Views/Images/Misc/certs_16x16.png"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <HeaderedContentControl>
            <HeaderedContentControl.Header>
                <Button Content="View certificate"
                        Command="{Binding ViewChainCertificateCommand}"
                        HorizontalAlignment="Left"
                        Width="100"/>
            </HeaderedContentControl.Header>
            <TreeView Name="tree"
                      SelectedItemChanged="onTreeViewSelectedItemChanged"
                      MouseDoubleClick="onTreeMouseDoubleClick"
                      ItemsSource="{Binding SelectedItem.Tree}"
                      ScrollViewer.CanContentScroll="True">
                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                        <StackPanel Orientation="Horizontal">
                            <Image Style="{StaticResource Img}" Height="16" Width="16"/>
                            <TextBlock  HorizontalAlignment="Stretch" Margin="5,0" Text="{Binding Value.Name}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="True"/>
                    </Style>
                </TreeView.ItemContainerStyle>
            </TreeView>
        </HeaderedContentControl>
        
        <GridSplitter Grid.Column="1"
                      ResizeBehavior="PreviousAndNext"
                      ResizeDirection="Columns"
                      Style="{StaticResource VerticalGridSplitter}"/>
        <Grid Grid.Column="2">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <HeaderedContentControl Header="Propagated errors:">
                <TextBox IsUndoEnabled="False"
                         UndoLimit="0"
                         FontFamily="Consolas"
                         IsReadOnly="True"
                         IsReadOnlyCaretVisible="True"
                         ScrollViewer.CanContentScroll="True"
                         TextWrapping="Wrap"
                         VerticalScrollBarVisibility="Auto"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Stretch"
                         Foreground="Orange"
                         Text="{Binding SelectedTreeItem.PropagatedErrorString, Mode=OneWay}"/>
            </HeaderedContentControl>
            <HeaderedContentControl Grid.Row="1" Header="Native errors:">
                <TextBox IsUndoEnabled="False"
                         UndoLimit="0"
                         FontFamily="Consolas"
                         IsReadOnly="True"
                         IsReadOnlyCaretVisible="True"
                         ScrollViewer.CanContentScroll="True"
                         TextWrapping="Wrap"
                         VerticalScrollBarVisibility="Auto"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Stretch"
                         Foreground="Red"
                         Text="{Binding SelectedTreeItem.NativeErrorString, Mode=OneWay}"/>
            </HeaderedContentControl>
        </Grid>
    </Grid>
</UserControl>
